package com.zhhs.project.act.appactivity.controller;


import com.zhhs.framework.web.domain.AjaxResult;
import com.zhhs.project.act.activity.domian.ActGiftVo;
import com.zhhs.project.act.activity.service.IActActivityPrizeService;
import com.zhhs.project.act.activity.service.IActActivityService;
import com.zhhs.project.act.appactivity.common.AssertUtil;
import com.zhhs.project.act.appactivity.domian.AppActivityDetails;
import com.zhhs.project.act.appactivity.domian.AppActivityPrize;
import com.zhhs.project.act.appactivity.domian.AppActivityRuleVo;
import com.zhhs.project.act.appactivity.domian.AppAwardRecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/wecom/mini-app")
public class AppActivityPrizeController {
    @Autowired
    private IActActivityService iActActivityService;
    @Autowired
    private IActActivityPrizeService actActivityPrizeService;
    /**
     * 活动规则
     * @param activityId
     * @return
     */
    @GetMapping("/activityRule")
    @ResponseBody
    public AjaxResult activityRule(Long activityId)
    {
        AppActivityRuleVo activityRuleVo = iActActivityService.activityRule(activityId);
        return AjaxResult.success(activityRuleVo);
    }

    /**
     * 中奖详情
     * @param awardId
     * @return
     */
    @GetMapping("/activityDetails")
    @ResponseBody
    public AjaxResult activityDetails(Long awardId)
    {
        AppActivityDetails appActivityDetails = iActActivityService.activityDetails(awardId);
        return AjaxResult.success(appActivityDetails);
    }

    /**
     * 中奖记录
     * @param userId
     * @param activityId
     * @return                                                                                      8
     */
    @GetMapping("/awardRecord")
    @ResponseBody
    public AjaxResult awardRecord(Long userId, Long activityId)
    {
        List<AppAwardRecordVo> appAwardRecordVoList = iActActivityService.awardRecord(userId, activityId);
        return AjaxResult.success(appAwardRecordVoList);
    }

    /**
     * 大转盘
     * @param userId
     * @param activityId
     * @return
     */
    @GetMapping("/activityPrizeList")
    @ResponseBody
    public AjaxResult activityPrizeList(Long userId, Long activityId)
    {
        AppActivityPrize appActivityPrizeList = iActActivityService.activityPrizeList(userId, activityId);
        return AjaxResult.success(appActivityPrizeList);
    }
    /**
     * 展示指定活动的获奖信息
     */
    @GetMapping("/historyGiftList/{activityId}")
    @ResponseBody
    public AjaxResult historyGiftList(@PathVariable Long activityId){
        AssertUtil.trueAssertErrorJson(activityId == null, "活动ID不能为空!");
        List<ActGiftVo> list=actActivityPrizeService.historyGiftList(activityId);
        if (list.size()<3){
            return AjaxResult.success();
        }
        return AjaxResult.success(list);
    }
}
